<%--
  Created by IntelliJ IDEA.
  User: zoud
  Date: 2016/10/27
  Time: 16:52
  To change this template use File | Settings | File Templates.
--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>Database Commons - Curation</title>
</head>
<body>
<h2 class="ui header">All databases</h2>
<div class="sub-header"><c:if test="${shortName != null}"><p>The shortName contains <strong><em>${shortName}</em></strong></p></c:if></div>
<div class="ui segment">
    Show
    <select name="length" class="length">
        <option value="10">10</option>
        <option value="25">25</option>
        <option value="50">50</option>
        <option value="100">100</option>
    </select>
    entities
    <br>
    <br>
    <table class="ui table celled">
        <thead>
        <tr>
            <th>Database name</th>
            <th>Data type(s)</th>
            <th>Major organism(s)</th>
            <th>Location</th>
            <th>Citation *</th>
            <th>Status</th>
            <th>z-index</th>
            <th>Action</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${biodbs}" var="db">
            <tr>
                <td><a href="${host}/database/id/${db.dbId}">${db.shortName}</a> <br>${db.fullName} <br><a
                        href="${db.url}" target="_blank"><i
                        class="fa fa-link"></i></a>
                </td>
                <td>
                    <ul>
                        <c:forEach items="${db.dataTypeList}" var="dt">
                            <li><a href="${host}/database/dataType/${dt.datatypeName}">${dt.datatypeName}</a>
                            </li>
                        </c:forEach>
                    </ul>
                </td>
                <td>
                    <ul>
                        <c:forEach items="${db.organismList}" var="osm">
                            <li><a href="${host}/database/organism/${osm.organismName}">${osm.organismName}</a>
                            </li>
                        </c:forEach>
                    </ul>
                </td>
                <td>${db.country}</td>
                <td>${db.getCitationNumber(db.publicationList)}</td>
                <td>
                    <c:if test="${db.status(db.httpStatuses) gt 0.95}">
                        <label class="label label-success">alive</label>
                    </c:if>
                    <c:if test="${db.status(db.httpStatuses) lt 0.95 && db.status(db.httpStatuses) gt 0.05}">
                        <label class="label label-warning">unstable</label>
                    </c:if>
                    <c:if test="${db.status(db.httpStatuses) lt  0.05 }">
                        <label class="label label-danger">dead</label>
                    </c:if>
                </td>
                <td><c:if test="${db.publicationList.size() gt 0}">
                    <fmt:formatNumber value="${db.getZindex(db.httpStatuses, db.publicationList)}"
                                      maxFractionDigits="2"/>
                </c:if>
                    <c:if test="${db.publicationList.size() eq 0}">
                        0
                    </c:if>
                </td>
                <td><a href="${host}/curator/db/edit/${db.dbId}" class="ui button mini blue"><i
                        class="ui icon pencil"></i>&nbsp;Curate</a></td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
    <c:if test="${page>0}">
        <ul class="ui pagination menu">
            <c:choose>
                <c:when test="${page-1>=1}">
                    <a href="${host}/curator/databases?length=${length}&page=1" class="item">First</a></li>
                    <a href="${host}/curator/databases?length=${length}&page=${page-1}" class="item">&laquo;</a></li>
                </c:when>
                <c:otherwise>
                    <a class="disabled item"><span>First</span></a>
                    <a class="disabled item"><span>&laquo;</span></a>
                </c:otherwise>
            </c:choose>
            <c:forEach var="i" begin="${pageLeft}" end="${pageRight}">
                <c:choose>
                    <c:when test="${page==i}">
                        <a class="active item"><span>${i}</span></a>
                    </c:when>
                    <c:otherwise>
                        <a class="item" href="${host}/curator/databases?length=${length}&page=${i}">${i}</a>
                    </c:otherwise>
                </c:choose>
            </c:forEach>
            <c:choose>
                <c:when test="${page+1<=pageTotal}">
                    <a class="item" href="${host}/curator/databases?length=${length}&page=${page+1}">&raquo;</a>
                    <a class="item" href="${host}/curator/databases?length=${length}&page=${pageTotal}">Last</a>
                </c:when>
                <c:otherwise>
                    <a class="disabled item"><span>&raquo;</span></a>
                    <a class="disabled item"><span>Last</span></a>
                </c:otherwise>
            </c:choose>
        </ul>
    </c:if>
</div>

<script>
    $(document).ready(function () {
        $('.length option').each(function () {
            if ($(this).val() == ${length}) {
                $(this).attr('selected', true);
            }
        });

        $('.length').change(function () {
            var length = $('.length').val();
            console.log('a=' + length);
            window.location.href = '${host}/curator/databases?length=' + length + '&page=${page}';
        });
    })
</script>
</body>
</html>

